package com.itheima.controller;

import com.itheima.Log.Log;
import com.itheima.common.PageBean;
import com.itheima.common.R;
import com.itheima.dto.StudentAddDto;
import com.itheima.dto.StudentQueryDto;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("students")
public class StudentController {
    @Autowired
    StudentService studentService;

    @GetMapping
    public R query(StudentQueryDto dto) {
        PageBean pageBean = studentService.query(dto);
        return R.ok(pageBean);
    }

    @PostMapping
    @Log
    public R add(@RequestBody StudentAddDto student){
    studentService.add(student);
    return R.ok();
    }

    @DeleteMapping("/{id}")
    @Log
    public R deleteid(@PathVariable Integer id){
        studentService.deleteid(id);
        return R.ok();
    }

    @GetMapping("/{id}")
    public R selectid(@PathVariable Integer id){
        Student student= studentService.selectid(id);
        return R.ok(student);
    }

    @PutMapping
    @Log
    public R update(@RequestBody Student student){
        studentService.update(student);
        return R.ok();
    }

    @PutMapping("/violation/{id}/{score}")
    @Log
    public R violation(@PathVariable Integer id,@PathVariable Integer score){
    studentService.violation(id,score);
        return R.ok();
    }

}
